#include <iostream>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

using namespace std;

#define FILENAME ".fifo"

int main()
{
    int fd = open(FILENAME, 0666);
    std::cout << "打开管道文件成功" << std::endl;

    if (fd < 0)
    {
        cerr << "error" << errno << " errno resaon " << strerror(errno) << endl;
        return 1;
    }
    std::cout << "客户端启动成功！！！"<< std::endl;

    int num = 0;
    std::string str;
    while (true)
    {
        std::cout << "Please enter: ";
        std::getline(cin, str);
        if (str == "quit")
        {
            break;
        }

        write(fd, str.c_str(), str.size());
        sleep(1);
    }

    close(fd);
    std::cout << "关闭管道文件成功" << std::endl;

   return 0;
}